Ext.define('PJ.view.remindmanagement.List', {
    extend: 'AM.default.DefaultList',
    alias: ['widget.remindmanagementList'],
    requires: ['AM.default.DefaultSearchForm',
               'AM.default.DateTime', 
               'AM.default.DefaultDateField',
               'AM.default.jsonp.DefaultLoadJsonp',//jsonp加载数据
		       'AM.default.DefaultActiveStateCombo'
               ],
    initComponent: function(){
    	var me= this;
    	this.columns = [{
    		header: '提醒内容',
    		dataIndex: 'remindValue',
    		flex: 1,
    		minWidth: 130,
    		renderer: function(value, meta, record){
    			if (record.get("lookState") == 1)
    				meta.style = "white-space:normal;cursor: pointer;color:blue;";
    			if (record.get("lookState") == 2)
    				meta.style = "white-space:normal;cursor: pointer;color:red;";
                meta.tdAttr = "data-qtip='" + value + "' remindId='"+record.get("remindId")+"'remindUserId='"+record.get("remindUserId")+"'";
    			return value;
    		},
    		listeners: {
    			click: function(g, clm){
    				var remindId = clm.getAttribute("remindId");
    				var remindUserId = clm.getAttribute("remindUserId");
    				win = Ext.create('PJ.view.remindmanagement.View', {
    					title: "查看提醒",
    					grid: me,
    					isReadOnly:true,
    					remindId:remindUserId
    				}).show();
    				var actionName = "load";
    				if(gj_onlineLearning_constant.loadType == "jsonp"){
    					actionName = "loadJsonp";
    				}
    				win.down("form").getForm().doAction(actionName,{
    					url:me.store.viewUrl,
    					params:{
    						searchRemindUserId: remindUserId,
    						remindId: remindId
    					},
    					success:function(f,action){
    						var data = action.response.responseText;
    	        			var json = gj_onlineLearning_constant.loadType=="ajax" ? Ext.decode(data, true) : action.response;
    	        			var form = win.down('form');	 
    	        			var baseForm = form.getForm();
    	                	Ext.Ajax.request({
    	                		url: showMsgUrl,
//    	              		url: 'workbench/orchid/data/msgData.jsons',
    	                		params: {},
    	                		success: function(response){
    	                			var data = response.responseText;
    	                			var jsonData = Ext.decode(data, true);
    	                			var remindUserNoReadCount = jsonData.data.remindUserNoReadCount;
    	                			var newsUserNoReadCount = jsonData.data.newsUserNoReadCount;
    	                			//me.setTitle("提醒管理("+remindUserNoReadCount+")")
    	                			 Ext.get("li_"+"8a10e7f9557b199401557b37dfbf0001").dom.innerHTML = '<span class="title"><b class="bull"></b>消息管理('+newsUserNoReadCount+')</span>'	
									 Ext.get("li_"+"4028809c52207e8a015220860c5r0002").dom.innerHTML = '<span class="title"><b class="bull"></b>提醒管理('+remindUserNoReadCount+')</span>'	
    	                		}
    	                	});
    	                	me.store.load();
    					}
    				});
    			}
    		}
    	},{
            header: '提醒类型',
            dataIndex: 'remindType',
            width: 100,
            renderer: function(value, meta, record){
            	meta.tdAttr = "data-qtip='" + value + "'";
            	return value;
            }
        },{
            header: '提醒时间',
            dataIndex: 't.createDate',
            width: 120,
            renderer: function(value, meta, record){
            	meta.tdAttr = "data-qtip='" + value + "'";
            	return value;
            }
        },{
            header: '读取状态',
            dataIndex: 'lookState',
            width: 100,
            renderer: function(value, meta, record){
            	if(value == 1){
            		return "<span style='color:blue'>已读</span>";
            	}else if(value == 2){
            		return "<span style='color:red'>未读</span>";
            	}
            }
        }];
    	
        this.store = Ext.create('PJ.'+ prototype +'.remindmanagement.List',{
        	isLoad: true
        });
        this.callParent(arguments);
        this.loadType = gj_onlineLearning_constant.loadType;//加载方式
    },
    /**
     * 删除
     */
    onDeleteClick: function(){
    	  var me = this;
      	  var store = me.getStore();
      	  var records = me.getSelectionModel().getSelection();
	      	Ext.Msg.confirm({
	    		  title:'提示',
	    		  msg:'您确定要删除这些数据吗?',
	    		  icon:Ext.Msg.WARNING,
	    		  buttons:Ext.Msg.OKCANCEL,
	    		  fn:function(id){
	    			  if(id=='ok'){
	    				  var remindIds= new Array();
	    				  Ext.Array.each(records,function(name,index){
	    					  remindIds.push(name.get('remindUserId'));
	    				  });
	    				  if(gj_onlineLearning_constant.loadType == "jsonp"){
	    					  var store1 = Ext.create('AM.default.jsonp.DefaultAjaxStore',{
	                      		loadType: gj_onlineLearning_constant.loadType,
	                              url: store.deleteUrl,
	                      		  extraParams: {
	                      			searchRemindUserIds: remindIds
	                              }
	                      	});
	    					  store1.load(function(rec, operation, success){
	    						  if(success){
	    							  Ext.Msg.alert('消息', '删除成功！', function(){
	    								  var store = me.getStore();
	    								  Ext.Ajax.request({
	    									  url: showMsgUrl,
//	    									  url: 'workbench/orchid/data/msgData.jsons',
	    									  params: {},
	    									  success: function(response){
	    										  var data = response.responseText;
	    										  var jsonData = Ext.decode(data, true);
	    										  var remindUserNoReadCount = jsonData.data.remindUserNoReadCount;
	    										  var newsUserNoReadCount = jsonData.data.newsUserNoReadCount;
	    										  //me.setTitle("提醒管理("+remindUserNoReadCount+")")
	    										  Ext.get("li_"+"8a10e7f9557b199401557b37dfbf0001").dom.innerHTML = '<span class="title"><b class="bull"></b>消息管理('+newsUserNoReadCount+')</span>'	
    											  Ext.get("li_"+"4028809c52207e8a015220860c5r0002").dom.innerHTML = '<span class="title"><b class="bull"></b>提醒管理('+remindUserNoReadCount+')</span>'	
	    									  }
	    								  });
	    								  store.load();
	    							  });
	    						  }else{
	    							  Ext.Msg.alert('消息', operation.error);
	    						  }
	    					  });
	    				  }else{
	    					  Ext.Ajax.request({
	    						  url:store.deleteUrl,
	    						  params: {
	    							  searchRemindUserIds: remindIds
	    	                       },
	    						  success:function(response){
	    							  var data=response.responseText;
	    							  var json=Ext.decode(data,true);
	    							  if(json.success){
	    								  Orchid.alert('提示','删除成功!',function(){
	    									  Ext.Ajax.request({
	    										  url: showMsgUrl,
//	    										  url: 'workbench/orchid/data/msgData.jsons',
	    										  params: {},
	    										  success: function(response){
	    											  var data = response.responseText;
	    											  var jsonData = Ext.decode(data, true);
	    											  var remindUserNoReadCount = jsonData.data.remindUserNoReadCount;
	    											  var newsUserNoReadCount = jsonData.data.newsUserNoReadCount;
	    											  //me.setTitle("提醒管理("+remindUserNoReadCount+")")
	    											  Ext.get("li_"+"8a10e7f9557b199401557b37dfbf0001").dom.innerHTML = '<span class="title"><b class="bull"></b>消息管理('+newsUserNoReadCount+')</span>'	
	    											  Ext.get("li_"+"4028809c52207e8a015220860c5r0002").dom.innerHTML = '<span class="title"><b class="bull"></b>提醒管理('+remindUserNoReadCount+')</span>'	
	    										  }
	    									  });
	    									  store.load();
	    								  });
	    							  }else{
	    								  Orchid.alert('提示',json.msg);
	    							  }
	    						  }
	    					  });
	    				  }
	    			  }
	    		  }
	    	  });
    	},
    listeners: {
		viewready: function(){
			var me = this;
			this.addDocked([{
				dock: 'top',
				xtype: "searchform",
				columnCount: 2,
				fieldDefaults: {
					labelAlign: 'right',
					labelWidth: 100
				},
				items: [{
                	xtype:"combo",
                    fieldLabel: "提醒类型",
                    name: "searchRemindType",
                    emptyText: "请选择",
                	store: Ext.create("Ext.data.ArrayStore", {
                		singleton: true,
                		fields: [{
                			name: 'value',
                			mapping: "dataCode",
                			type: 'string'
                		}, {
                			name: 'text',
                			mapping: "dataName",
                			type: 'string'
                		}],
                		proxy: {
                			type: gj_onlineLearning_constant.loadType,
                			url: me.store.remindTypeUrl + '?typeCode=txlb',
                			reader: Ext.create('Ext.data.reader.Json', {
                				type: 'json',
                				root: 'data',
                				successProperty: 'success'
                			})
                		},
                		autoLoad: true
                	}),
        			valueField: 'value',
        			displayField: 'text',
        			editable: false,
        			defaultActive: false
                },{
					xtype: "combo",
					fieldLabel: '读取状态',
					name: "searchLookState",
					store: Ext.create("Ext.data.ArrayStore", {
						fields: ['value', 'text'],
						data: [[1, '已读'],[2,'未读']]
					}),
					valueField: 'value',
					displayField: 'text',
					editable: false,
					emptyText: "请选择"
				}/*,{
                	xtype:"combo",
                    fieldLabel: "提醒分类",
                    name: "searchRemindCategory",
                	store: Ext.create("Ext.data.ArrayStore", {
                		singleton: true,
                		fields: [{
                			name: 'value',
                			mapping: "dataCode",
                			type: 'string'
                		}, {
                			name: 'text',
                			mapping: "dataName",
                			type: 'string'
                		}],
                		proxy: {
                			type: gj_onlineLearning_constant.loadType,
                			url:me.store.remindCategoryUrl + '?typeCode=txfl',
                			reader: Ext.create('Ext.data.reader.Json', {
                				type: 'json',
                				root: 'data',
                				successProperty: 'success'
                			})
                		},
                		autoLoad: true
                	}),
        			valueField: 'value',
        			displayField: 'text',
        			editable: false,
        			emptyText: "请选择",
        			defaultActive: false
                }*//*,{
                	xtype:"combo",
                    fieldLabel: "提醒类型",
                    name: "searchTrainingDeptName",
                	store: Ext.create("Ext.data.ArrayStore", {
                		singleton: true,
                		fields: [{
                			name: 'value',
                			mapping: "dataName",
                			type: 'string'
                		}, {
                			name: 'text',
                			mapping: "dataName",
                			type: 'string'
                		}],
                		proxy: {
                			type: gj_onlineLearning_constant.loadType,
                			url: gj_onlineLearning_constant.holdUniversitiesUrl + '?typeCode=jbyx',
                			reader: Ext.create('Ext.data.reader.Json', {
                				type: 'json',
                				root: 'data',
                				successProperty: 'success'
                			})
                		},
                		autoLoad: true
                	}),
        			valueField: 'value',
        			displayField: 'text',
        			editable: false,
        			defaultActive: false
                }*/],
				grid: this
			},{
				xtype: 'toolbar',
				dock: 'top',
				displayInfo: true,
				items: [{
					text: '删除',
					iconCls: 'deleteIco',
					itemId: this.oldId + "Delete",
					disabled: true,
					scope: this,
					handler: this.onDeleteClick
				},"->", this.countSelectPanel]
			}]);
		}
    }
});
